<template>
  <div class="aui-card-list">
    <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}"
      @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item :label="$t('sysRuleSort.name')">
          <el-input v-model="dataForm.name" :placeholder="$t('sysRuleSort.name')" clearable></el-input>
        </el-form-item>
      </el-col>
    </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :setting="{immediate:true}">
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('sys:sysRuleSort:save')" type="primary" @click="addOrUpdateHandle()">{{
            $t('add') }}
          </el-button>
          <el-button v-if="$hasPermission('sys:sysRuleSort:delete')" type="danger" @click="deleteHandle()">{{
            $t('deleteBatch') }}
          </el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
        <vxe-table :loading="dataListLoading" :data="dataList" ref="xTable" auto-resize class="vxe-table-element"
          @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex">
          <vxe-table-column type="checkbox" width="50" align="center"></vxe-table-column>
          <vxe-table-column field="name" title="sysRuleSort.name">
          </vxe-table-column>
          <vxe-table-column field="value" title="sysRuleSort.value">
            <template slot-scope="scope">
              <el-button type="text" @click="goto(scope.row)">{{scope.row.value}}
              </el-button>
            </template>
          </vxe-table-column>
          <vxe-table-column field="sort" title="sysRuleSort.sort" width="60" align="center"></vxe-table-column>
          <vxe-table-column field="status" title="sysRuleSort.status" width="80" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status == 0" size="small" type="danger">{{ $t('dict.status0') }}</el-tag>
              <el-tag v-else size="small" type="success">{{ $t('dict.status1') }}</el-tag>
            </template>
          </vxe-table-column>
          <vxe-table-column title="handle" fixed="right" width="120" align="center">
            <template slot-scope="scope">
              <el-button v-if="$hasPermission('sys:sysRuleSort:update')" type="text" size="small" icon="el-icon-edit"
                @click="addOrUpdateHandle(scope.row.id)">{{
                $t('update') }}
              </el-button>
              <el-button v-if="$hasPermission('sys:sysRuleSort:delete')" type="text" size="small" icon="el-icon-delete"
                @click="deleteHandle(scope.row.id)">{{
                $t('delete') }}
              </el-button>
            </template>
          </vxe-table-column>
        </vxe-table>
        <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
          layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle">
        </el-pagination>
        <!-- 弹窗, 新增 / 修改 -->
        <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
      </div>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './sysRuleSort-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/sys/sysRuleSort/page',
        getDataListIsPage: true,
        deleteURL: '/sys/sysRuleSort',
        deleteIsBatch: true
      },
      dataForm: {
        name: ''
      }
    }
  },
  methods: {
    // 执行临时路由
    goto (item) {
      // 添加子级路由
      var router = {
        name: 'sys-ruledata', // 路由名称
        oldName: 'sys-sysRuleSort', // 原路由地址
        id: item.id, // 路由标识值
        path: 'sys/ruledata', // component地址
        title: '权限规则 - ' + item.name // tab名称
      }
      var params = {
        ruleSort: item.value
      }
      this.openNewTab(this.$router, router, params)
    }
  },
  components: {
    AddOrUpdate
  }
}
</script>
